﻿using Microsoft.Extensions.Configuration;

namespace Handday.Erp.Core
{
    /// <summary>
    /// 公共API接口基地址
    /// </summary>
    public class BaseApiUrl
    {
        private readonly IConfiguration _configuration;

        /// <summary>
        /// ctor
        /// </summary>
        public BaseApiUrl(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        /// <summary>
        /// 指掌平台基地址
        /// </summary>
        public string HanddayBaseUrl
        {
            get
            {
                var url = _configuration["HanddayBaseUrl"];
                return ToUrl(url);
            }
        }

        /// <summary>
        /// 旧crm服务地址
        /// </summary>
        public string CrmApiUrl
        {
            get
            {
                var url = _configuration["CrmApiUrl"];
                return ToUrl(url);
            }
        }

        /// <summary>
        /// scrm webui 地址
        /// </summary>
        public string SCrmWebUrl
        {
            get
            {
                var url = _configuration["SCrmWebUrl"];
                return ToUrl(url);
            }
        }

        /// <summary>
        /// scrm crm平台服务地址
        /// </summary>
        public string SCrmApiUrl
        {
            get
            {
                var url = _configuration["ScrmCrmApiUrl"];
                return ToUrl(url);
            }
        }

        /// <summary>
        /// 订货服务地址
        /// </summary>
        public string SmartOrderApiUrl
        {
            get
            {
                var url = _configuration["SmartOrderApiUrl"];
                return ToUrl(url);
            }
        }

        /// <summary>
        /// 认证中心地址
        /// </summary>
        public string PassportApiUrl
        {
            get
            {
                var url = _configuration["Authority"];
                return ToUrl(url);
            }
        }

        /// <summary>
        /// 平台服务地址
        /// </summary>
        public string PlatformApiUrl
        {
            get
            {
                var url = _configuration["PlatformApiUrl"];
                return ToUrl(url);
            }
        }

        /// <summary>
        /// 官网站点地址
        /// </summary>
        public string WebSiteUrl
        {
            get
            {
                var url = _configuration["WebSiteUrl"];
                return ToUrl(url);
            }
        }

        /// <summary>
        /// 附件服务地址
        /// </summary>
        public string AnnexServicesUrl
        {
            get
            {
                var url = _configuration["AnnexServices"];
                return ToUrl(url);
            }
        }

        /// <summary>
        /// 附件CloudView地址
        /// </summary>
        public string CloudViewRootUrl => $"{AnnexServicesUrl}Annex/CloudView?path=";

        /// <summary>
        /// 文件服务地址
        /// </summary>
        public string FileServiceUrl
        {
            get
            {
                var url = _configuration["FileServiceUrl"];
                return ToUrl(url);
            }
        }

        /// <summary>
        /// Erp转换器URL
        /// </summary>
        public string ErpTransferUrl
        {
            get
            {
                var url = _configuration["ErpTransferUrl"];
                return ToUrl(url);
            }
        }

        /// <summary>
        /// Erpjoint项目url
        /// </summary>
        public string ErpjointApiUrl
        {
            get
            {
                var url = _configuration["ErpjointApiUrl"];
                return ToUrl(url);
            }
        }

        #region private methods

        /// <summary>
        /// 获取处理过的URL
        /// </summary>
        private string ToUrl(string url)
        {
            return !string.IsNullOrWhiteSpace(url) ? url.Trim().TrimEnd('/') + "/" : string.Empty;
        }

        #endregion private methods
    }
}